package com.nbsaas.boot.app.rest.convert;

import com.nbsaas.boot.app.api.domain.simple.AppUserRoleSimple;
import com.nbsaas.boot.app.data.entity.AppUserRole;
import com.nbsaas.boot.rest.api.Converter;

/**
 * 应用用户角色-列表对象转换器
 */

public class AppUserRoleSimpleConvert implements Converter<AppUserRoleSimple, AppUserRole> {


    @Override
    public AppUserRoleSimple convert(AppUserRole source) {
        AppUserRoleSimple result = new AppUserRoleSimple();


        try {
            if (source.getApp() != null) {
                result.setApp(source.getApp().getId());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getRole() != null) {
                result.setRole(source.getRole().getId());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getApp() != null) {
                result.setAppName(source.getApp().getName());
            }
        } catch (Exception ignored) {
        }


        try {
            if (source.getRole() != null) {
                result.setRoleName(source.getRole().getName());
            }
        } catch (Exception ignored) {
        }

        result.setId(source.getId());
        result.setUser(source.getUser());
        result.setTenant(source.getTenant());


        return result;
    }

}